%%
x=[2,4,6,8,10,12,14,16,18,20];
y1=cirshift(x,-4,10);
y2=cirshift(x,4,12);

figure;
subplot(121);stem(0:9, y1, '.');
subplot(122);stem(0:11, y2, '.');

%%
x=[2,4,6,8,10,12,14,16,18,20];N=13;
x=[x,zeros(1,N-length(x))];nx=0:N-1;
y=x(mod(-nx,N)+1);
figure;
stem(0:N-1, y, '.');

%%
% x=[2,4,6,8,10,12,14,16,18,20]，求N=10的DFT矩阵，并求该序列的DFT，并绘制x的幅度与相位
x=[2,4,6,8,10,12,14,16,18,20];
N=10;
Xk_DFT=dftmtx(N).*x;
disp(dftmtx(N));
disp(Xk_DFT);

% 绘制x的幅度与相位
figure;
subplot(121);stem(0:N-1, abs(Xk_DFT), '.');title('幅度');
subplot(122);stem(0:N-1, angle(Xk_DFT), '.');title('相位');

%% 
x=[2,4,6,8,10,12,14,16,18,20];N=10;
Xk_DFT=dft(x, N);
disp(Xk_DFT);
figure;
subplot(121);stem(0:N-1, abs(Xk_DFT), '.');title('幅度');
subplot(122);stem(0:N-1, angle(Xk_DFT), '.');title('相位');

%%
x=[6, 4+3j, -3-2j, 2-j, 4, 2+j, -3+2j, 4-3j];N=8;
idft=conj(dftmtx(N))/N;
disp(idft);
xk_IDFT=idft.*x;
disp(xk_IDFT);
figure;
stem(0:N-1, xk_IDFT, '.');

%%
X=[6, 4+3j, -3-2j, 2-j, 4, 2+j, -3+2j, 4-3j]';N=length(X);
xn_idft=idft(X, N);
disp(xn_idft);
figure;
stem(0:N-1, xn_idft, '.');

%%
%x=[2,4,6,8,10,12] h=[2,-5,8,3]使用时域方法
xn=[2,4,6,8,10,12];
hn=[2,-5,8,3];

y1=circonvt(xn,hn,6);
y2=circonvt(xn,hn,9);
y3=circonvt(xn,hn,12);
y4=conv(xn,hn);

figure;
subplot(221);stem(0:5, y1, '.');title('6点圆周卷积和');
subplot(222);stem(0:8, y2, '.');title('9点圆周卷积和');
subplot(223);stem(0:11, y3, '.');title('12点圆周卷积和');
subplot(224);stem(0:8, y4, '.');title('线性卷积和');

%%
% x=[2,4,6,8,10,12] h=[2,-5,8,3]使用频域方法
xn=[2,4,6,8,10,12];
hn=[2,-5,8,3];

y1=fd_circonvt(xn,hn,6);
y2=fd_circonvt(xn,hn,9);
y3=fd_circonvt(xn,hn,12);
y4=fd_conv(xn,hn);

figure;
subplot(221);stem(0:5, y1, '.');title('6点圆周卷积和');
subplot(222);stem(0:8, y2, '.');title('9点圆周卷积和');
subplot(223);stem(0:11, y3, '.');title('12点圆周卷积和');
subplot(224);stem(0:8, y4, '.');title('线性卷积和');